package de.koller.retrograde;

import de.koller.aframe.util.node.NodeA;
import de.koller.aframe.util.thread.ICommand;
import de.koller.aframe.util.thread.ThreadRootHandle;
import de.koller.oceanFramework.tree.Child;
import de.koller.retrograde.response.ResponseRoot;
import java.util.Random;

public class RRoot extends NodeA {
	
	public static final Random RND = new Random();
	
	private final ThreadRootHandle mainThread = new ThreadRootHandle( "mainServer" );
	@Child public final ResponseRoot response = new ResponseRoot();
	
	public static void startServer() {
		RRoot root = new RRoot();
		root.start();
	}
	
	private RRoot() {
		
	}
	
	public void start() {
		mainThread.start();
		
		this.call( new ICommand() {
			@Override public void handle( Object... params ) {
				initalize();
			}
		} );
	}

	@Override
	protected void init() {
		super.init();
		
		this.setIgnoreChildRender( true );
	}

	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
	}
	
	public void call( ICommand command ) {
		mainThread.call( command );
		
		mainThread.call( new ICommand() {
			@Override public void handle( Object... params ) {
				updating( 1 );
			}
		} );
	}
	
}
